3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * Form to edit user preferences.
26 class PreferencesFormOOUI
extends OOUIHTMLForm
{
27 // Override default value from HTMLForm
28 protected $mSubSectionBeforeFields = false;
30 private $modifiedUser;
35 public function setModifiedUser( $user ) {
36 $this->modifiedUser
= $user;
42 public function getModifiedUser() {
43 if ( $this->modifiedUser
=== null ) {
44 return $this->getUser();
46 return $this->modifiedUser
;
51 * Get extra parameters for the query string when redirecting after
56 public function getExtraSuccessRedirectParameters() {
64 function wrapForm( $html ) {
65 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
67 return parent
::wrapForm( $html );
73 function getButtons() {
74 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
78 $html = parent
::getButtons();
80 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
81 $t = $this->getTitle()->getSubpage( 'reset' );
83 $html .= new OOUI\
ButtonWidget( [
85 'id' => 'mw-prefs-restoreprefs',
86 'label' => $this->msg( 'restoreprefs' )->text(),
87 'href' => $t->getLinkURL(),
88 'flags' => [ 'destructive' ],
92 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
99 * Separate multi-option preferences into multiple preferences, since we
100 * have to store them separately
104 function filterDataForSubmit( $data ) {
105 foreach ( $this->mFlatFields
as $fieldname => $field ) {
106 if ( $field instanceof HTMLNestedFilterable
) {
107 $info = $field->mParams
;
108 $prefix = $info['prefix'] ??
$fieldname;
109 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
110 $data["$prefix$key"] = $value;
112 unset( $data[$fieldname] );
119 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
120 $layout = parent
::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
122 $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
123 $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
129 * Get the whole body of the form.
134 foreach ( $this->mFieldTree
as $key => $val ) {
135 if ( !is_array( $val ) ) {
136 wfDebug( __METHOD__
. " encountered a field not attached to a section: '$key'" );
139 $label = $this->getLegend( $key );
141 $this->getHeaderText( $key ) .
142 $this->displaySection(
143 $this->mFieldTree
[$key],
145 "mw-prefsection-$key-"
147 $this->getFooterText( $key );
149 $tabPanels[] = new OOUI\
TabPanelLayout( 'mw-prefsection-' . $key, [
150 'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
152 'content' => new OOUI\
FieldsetLayout( [
153 'classes' => [ 'mw-prefs-section-fieldset' ],
154 'id' => "mw-prefsection-$key",
158 'content' => new OOUI\
HtmlSnippet( $content )
167 $indexLayout = new OOUI\
IndexLayout( [
170 'autoFocus' => false,
171 'classes' => [ 'mw-prefs-tabs' ],
173 $indexLayout->addTabPanels( $tabPanels );
175 return new OOUI\
PanelLayout( [
178 'classes' => [ 'mw-prefs-tabs-wrapper' ],
179 'content' => $indexLayout
184 * Get the "<legend>" for a given section key. Normally this is the
185 * prefs-$key message but we'll allow extensions to override it.
189 function getLegend( $key ) {
190 $legend = parent
::getLegend( $key );
191 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
196 * Get the keys of each top level preference section.
197 * @return string[] List of section keys
199 function getPreferenceSections() {
200 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );